<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.text.Format" %>
<%@ page import="java.util.Date" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.Collections" %>
<%@ page import="net.tutwiz.model.Comment" %>
<%@ page import="net.tutwiz.model.User" %>
<%@ page import="com.google.gson.GsonBuilder" %>
<%@ page import="com.google.gson.ExclusionStrategy" %>
<%@ page import="com.google.gson.Gson;" %>
<%
	response.setContentType("application/json");
	response.setCharacterEncoding("utf-8");
%>

<%
	String returnValue = "{";
	List<Comment> comments = (List<Comment>)request.getAttribute("parameters");
	returnValue += "\"comments\": [";

	Collections.sort(comments);
        
        Format dateFormat = new SimpleDateFormat("MM/dd/yy HH:mm");
	
	for(Comment c : comments) {
		returnValue += "{";
		returnValue += "\"id\":\"" + c.getId() + "\",";
                returnValue += "\"text\":\"" + c.getText() + "\",";
                returnValue += "\"title\":\"" + c.getTitle() + "\",";
                returnValue += "\"date\":\"" + dateFormat.format(c.getDate()) + "\",";
                returnValue += "\"createdBy\": {";
                returnValue +=      "\"name\":\"" + c.getCreatedBy().getName() + "\", ";
                returnValue +=      "\"id\":\"" + c.getCreatedBy().getID();
                returnValue +=      "\"}";
		returnValue += "},";
	}
	returnValue = returnValue.substring(0, returnValue.length()-1);
	returnValue += "]}";
%>
<%= returnValue %>
